package com.ccmusic.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * cyf  处理用户退出登录的操作
 * Servlet implementation class loginOutServlet
 */
@WebServlet("/loginOutServlet")
public class loginOutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 HttpSession session= request.getSession();
		 //session信息为空时，直接重定向到主页面
		 if(session==null) {
			 response.sendRedirect("CCMusicSys/homePage.jsp");
			 return;
		 }
		 //session不为空时，清除session中的所有信息，重定向到主页面
		 session.invalidate();
		 response.sendRedirect("CCMusicSys/homePage.jsp");
	}
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
